package com.mall.common.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mall.b2c.util.JsonDataGridHelper;
import com.mall.common.bean.Pager;
import com.mall.common.bean.SearchFilter;
import com.mall.common.enums.OperateType;
import com.mall.common.service.OperateLogService;
import com.mall.common.util.EnumUtils;
import com.mall.common.web.Servlets;

@Controller
@RequestMapping("/admin/system/operateLog")
public class OperateLogController extends BaseController {
	@Resource private OperateLogService operateLogService;

	@RequestMapping("/list")
	public String list(Model model){
		model.addAttribute("operateTypes",
				EnumUtils.enumProp2I18nList(OperateType.class));
		return "/admin/system/operateLog/list";
	}
	
	@RequestMapping(value="/queryData", method=RequestMethod.POST)
	@ResponseBody
	public Pager queryData(Pager pager, HttpServletRequest request){
    	Map<String, Object> filterParams = Servlets.getParametersStartingWith(request);
		List<SearchFilter> filters = SearchFilter.parse(filterParams);
    	pager = operateLogService.findPage(pager, filters);
		return JsonDataGridHelper.createJSONData(pager);
    }
}
